package com.wsoft.dc.controller;

import com.wsoft.dc.query.config.*;
import com.wsoft.dc.service.IDcConfigService;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 待办中心配置 前端控制器
 * @author Z001
 * @since 2024年12月17日 16:18:10
 */
@RestController
@Tag(name = "基本配置")
@RequestMapping("/dc/config")
public class DcConfigController {

    @Resource
    private IDcConfigService configService;

    @Operation(summary = "新增待办配置", description = "新增待办配置")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ConfigInsertQuery query) {
        boolean b = configService.insertConfig(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改待办配置", description = "修改待办配置")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ConfigUpdateQuery query) {
        boolean b = configService.updateConfig(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改是否启用", description = "修改是否启用")
    @PostMapping("/updateEnable")
    public ResponseResult updateEnable(@RequestBody @Valid ConfigUpdateEnableQuery query) {
        boolean b = configService.updateEnable(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "待办配置详情页面", description = "待办配置详情页面")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(configService.getConfigInfo(id));
    }

    @Operation(summary = "删除待办配置", description = "删除待办配置")
    @GetMapping("/delete")
    public ResponseResult dropConfig(@RequestParam("id") Long id) {
        boolean b = configService.deleteConfig(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "查询待办配置列表", description = "查询待办配置列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ConfigListQuery query) {
        return ResponseResult.success(ResponsePage.restPage(configService.listConfig(query)));
    }


    @Operation(summary = "获取模块下所有的配置类型", description = "获取模块下所有的配置类型")
    @GetMapping("/getType")
    public ResponseResult getType(@RequestParam("moduleId") Long moduleId) {
        return ResponseResult.success(configService.getType(moduleId));
    }


    @Operation(summary = "获取所有模块id", description = "获取所有模块id")
    @PostMapping("/allDcModule")
    public ResponseResult allDcModule() {
        return ResponseResult.success(configService.allDcModule());
    }


    @Operation(summary = "测试list接口", description = "测试list接口")
    @PostMapping("/checkList")
    public ResponseResult checkList(@RequestBody ConfigCheckQuery query) {
        return ResponseResult.success(configService.checkList(query));
    }

    @Operation(summary = "测试count接口", description = "测试count接口")
    @PostMapping("/checkCount")
    public ResponseResult checkCount(@RequestBody ConfigCheckQuery query) {
        return ResponseResult.success(configService.checkCount(query));
    }

}
